<?php

//PURPOSE OF CODE - 
//THIS CODE HAS ALL THE FUNCTIONS THAT ARE REQUIRED FOR FETCHING VARIONS CONTENT RELATED INFO
//THIS FILE IS INCLUDED IN NEW_FUNCTIONS.PHP3 WHICH IN TURN IS INCLUDED IN ALMOST ALL THOSE
//PAGES RELATED TO WAP, SO DEFINING A FUNCTION HERE WOULD MAKE IT AVAILABLE ALMOST EVERYWHERE.

//	FUNCTION NAME : FDA_GET_MIME_TYPE
//	INPUT PARAMETERS : $EXTN - THE EXTENSION OF THE FILE
//	OUTPUT PARAMETERS : $MIME_TYPE - THE MIME TYPE REQUIRED IN THE HEADERS DURING CONTENT DELIVERY

function fda_get_mime_type($extn)
{
	if(($extn=='amr')||($extn=='awb'))
		$mime_type = "audio/amr-wb";						//	FOR TRUETONES
	elseif($extn=='jad')
		$mime_type = "text/vnd.sun.j2me.app-descriptor";	//	FOR JAVA GAMES
	elseif($extn=='nol')
		$mime_type = "image/vnd.nok-oplogo-color";			//	FOR COLORLOGOS
	elseif($extn=='sis')
		$mime_type = "application/x-sis";					//	FOR THEMES (SYMBIAN OS)
	elseif($extn=='thm')
		$mime_type = "application/vnd.eri.thm";				//	FOR THEMES (SONY ERICSSON)
	elseif($extn=='3gp')
		$mime_type = "video/3gpp";							//	FOR VIDEOS
	elseif(($extn=='mid')||($extn=='midi'))
		$mime_type = "audio/midi";							//	FOR POLYTONES
	elseif($extn=='gif')
		$mime_type = "image/gif";							//	FOR WALLPAPERS/ANIMATIONS
	elseif($extn=='jpg')
		$mime_type = "image/jpeg";							//	FOR WALLPAPERS
	elseif($extn=='mp3')
		$mime_type = "audio/mpeg";							//	FOR MP3
	elseif($extn=='mmf')
		$mime_type = "application/vnd.smaf";				// 	FOR POLYTONES/TRUETONES
	elseif($extn=='rmf')
		$mime_type = "audio/x-rmf";							//	FOR POLYTONES/TRUETONES
	elseif($extn=='xmf')
		$mime_type = "audio/mobile-xmf";					//	FOR POLYTONES/TRUETONES
	elseif($extn=='mp4')
		$mime_type = "video/mp4";							//	FOR VIDEOS
	elseif($extn=='flv')
		$mime_type = "video/x-flv";							//	FOR VIDEOS
	elseif($extn=='apk')
		$mime_type = "application/vnd.android.package-archive";		//	FOR ANDROID APP
		
	return $mime_type;
}
	

//FUNCTION NAME : FDA_GET_SUPPORT_ID_VAR_NAME
//INPUT PARAMETERS : $TYPE_ID - THE TYPE ID OF THE CONTENT
//OUTPUT PARAMETERS : $SUPPID - THE NAME OF THE VARIABLE WHICH HOLDS THE SUPPORT ID (GROUP ID)

function fda_get_support_id_var_name($type_id)
{
	if($type_id==1) 		$suppId = "wp_support_id";
	elseif($type_id==2)		$suppId = "poly_support_id";
	elseif($type_id==3)		$suppId = "tr_support_id";
	elseif($type_id==4)		$suppId = "mp_support_id";
	elseif($type_id==5)		$suppId = "ani_support_id";
	elseif($type_id==6)		$suppId = "cl_support_id";
	elseif($type_id==7)		$suppId = "gm_support_id";
	elseif($type_id==8) 	$suppId = "tm_support_id";
	elseif($type_id==10)	$suppId = "sms_poly_support_id";
	elseif($type_id==11)	$suppId = "sms_true_support_id";
	elseif($type_id==12)	$suppId = "sms_mp3_support_id";
	elseif($type_id==14)	$suppId = "vi_support_id";
	elseif($type_id==15)	$suppId = "fla_support_id";
	elseif($type_id==19)	$suppId = "sms_tone_support_id";
	elseif($type_id==33)	$suppId = "vcal_support_id";
	
	return $suppId;
}
	

//Function Name : fda_serve_content
//Input Parameters : 	$mime_type - the mime type of the content
//					$file_path - the physical file path of the content
//					$file_name - the name of the file (the content will be saved with this name at the user end)
//					$type_id - type id of the content
//					$group_id - group id of the handset for the corresponding type
//					$client_id - client id
//Output Parameters : None

function fda_serve_content($mime_type, $file_path, $file_name, $type_id = 0, $group_id = 0, $filesize = 0)
{
	$url = 'http://mobile-content.vvidiacom.com/'.$file_path.'';
	header('Content-type: '.$mime_type);
	//header('content-length: '.$filesize);
	header('Content-Disposition: attachment; filename="'.$file_name.'"');
	readfile($url);
}

//	FUNCTION NAME : FDA_GET_CONTENT_DETAILS_FROM_CONTID
//	INPUT PARAMETERS : 	$CONT_ID - CONTENT ID OF THE CONTENT
//						$HS_ID - HANDSET ID
//						$CONNECTION - DB CONNECTION OBJECT
//	OUTPUT PARAMETERS : $RET_VAL = DISP_NAME<#>TYPE ID<#>SUB CAT<#>DESCRIPTION<#>VENDOR ID<#>ACTIVE<#>DIST RIGHTS<#>DATA TABLE<#>COST PTR<#>FILE NAME<#>GAME CODE<#>GROUP ID<#>RETURN FLAG<#>RETURN DESC

function fda_get_content_details_from_contid($cont_id, $hs_id = 0, $connection)
{
	$return_err_desc = "";
	$return_success_flag = 0;
	
	
	if($hs_id == 0)
	{
		$select_cont_master =  "select content_master.cont_id,content_master.disp_name,content_master.type_id,content_master.sub_cat,content_master.description,content_master.vendor_id,content_master.active,content_master.distribution_rights,type_master.data_table,content_master.cost_ptr,content_master.disp_name from content_master ,handest_master ,type_master ,group_master where content_master.cont_id = $cont_id and content_master.type_id = type_master.type_id group by content_master.cont_id";
		$result = mysql_query($select_cont_master,$connection);
		list($cont_id,$disp_name,$type_id,$sub_cat,$desc,$vendor_id,$active,$distribution_rights,$data_table,$cptr,$disp_name) = 										mysql_fetch_row($result);
		
		switch($type_id)
		{
			case 15:
				$group_id = 271; // Becasue if user FLA compatible then serve content 234.... 234 group id for less than 1 mb fla
			break;
			case 3:
				$group_id = 40; 
			break;
			
			case 2:
				$group_id = 31; 
			break;
			case 4:
				$group_id = 51; 
			break;
			case 1:
				$group_id = 62; 
			break;
			case 14:
				$group_id = 143; 
			break;
			
			case 5:
				$group_id = 15;
			break;
		}
	}
	else
	{
		$select_cont_master =  "select content_master.cont_id,handest_master.hs_id,content_master.disp_name,content_master.type_id,content_master.sub_cat,content_master.description,content_master.vendor_id,content_master.active,content_master.distribution_rights,type_master.data_table,content_master.cost_ptr,content_master.disp_name from content_master ,handest_master ,type_master ,group_master where content_master.cont_id = $cont_id and handest_master.hs_id = $hs_id and content_master.type_id = type_master.type_id group by content_master.cont_id";
		$result = mysql_query($select_cont_master,$connection);
		list($cont_id,$hs_id,$disp_name,$type_id,$sub_cat,$desc,$vendor_id,$active,$distribution_rights,$data_table,$cptr,$disp_name) = 										mysql_fetch_row($result);
		
		$select_handset_group =  "select group_id from handset_group where hs_id = $hs_id and type_id = $type_id";
		$result2 = mysql_query($select_handset_group,$connection);
		list($group_id) = mysql_fetch_row($result2);
		if($group_id == '')
		{
			$group_id = 0;
		}
	}
	
	if($group_id > 0)
	{
		 switch ($type_id)
		{
			case 15:
				$group_id = 271; // Becasue if user FLA compatible then serve content 234.... 234 group id for less than 1 mb fla
			break;
			case 3:
				$group_id = 40; // Becasue if user FLA compatible then serve content 234.... 234 group id for less than 1 mb fla
			break;
			case 4:
				$group_id = 51; // Becasue if user FLA compatible then serve content 234.... 234 group id for less than 1 mb fla
			break;
			
			case 2:
				$group_id = 31; // Becasue if user FLA compatible then serve content 234.... 234 group id for less than 1 mb fla
			break;
			case 14:
				$group_id = 143; // Becasue if user FLA compatible then serve content 234.... 234 group id for less than 1 mb fla
			break;
			/*case 1:
				$group_id = 62; // Becasue if user FLA compatible then serve content 234.... 234 group id for less than 1 mb fla
			break;
			
			case 5:
				$group_id = 120; // Becasue if user FLA compatible then serve content 234.... 234 group id for less than 1 mb fla
			break;*/
		}
	}
	else
	{
		//Temparory
		 switch ($type_id)
		{
			case 14:
				$group_id = 141; // Becasue if user FLA compatible then serve content 234.... 234 group id for less than 1 mb fla
			break;
		}
	}
	
	$select_data_table =  "select file_name, file_size from ".strtolower($data_table)." where cont_id= $cont_id and group_id=$group_id";
	$result3 = mysql_query($select_data_table,$connection);
	list($file_name,$file_size) = mysql_fetch_row($result3);		
	
	//append any new variable to the END of this value and NOT IN THE MIDDLE
	$ret_val = "$cont_id<#>$type_id<#>$sub_cat<#>$desc<#>$vendor_id<#>$active<#>$distribution_rights<#>$data_table<#>$cptr<#>$file_name<#>$game_code<#>$group_id<#>$return_success_flag<#>$disp_name";
	
	return $ret_val;
}

?>
